package com.imooc.cloud.mall.practice.categoryproduct.config;

import com.imooc.cloud.mall.practice.categoryproduct.common.ProductConstant;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 描述：     配置地址映射
 */
@Configuration
public class ImoocMallWebMvcConfig implements WebMvcConfigurer {

    /**
     * 添加静态资源处理器，用于映射静态资源的访问路径和物理路径。
     * @param registry 静态资源处理器注册表
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/admin/**").addResourceLocations("classpath:/static/admin/");
        // 映射 "/images/**" 请求路径到指定的物理路径，用于访问上传的图片资源
        registry.addResourceHandler("/images/**").addResourceLocations(
                "file:"+ ProductConstant.FILE_UPLOAD_DIR);
        registry.addResourceHandler("swagger-ui.html").addResourceLocations(
                "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/");

    }
}
